<?php

/**
 * sellwish actions.
 *
 * @package    ppstool
 * @subpackage sellwish
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class sellwishActions extends sfActions
{


	public function executeIndex(sfWebRequest $request)
	{
		$this->getUser()->setAttribute('progress', 30);
		if ($this->getUser()->getAttribute('xmlin')) {
			$this->xml = simplexml_load_string($this->getUser()->getAttribute('xmlin'));
			$this->n= (int)$this->xml->attributes()->period[0];
		}
		else {
			$this->getUser()->setFlash('error', "Bitte zuerst den Import ausführen!", true);
			$this->redirect("import/index");
		}
	}

	public function executeSavesellwish(sfWebRequest $request)
	{
		$error = false;

		//Produkt 1
		if ((int)$request->getParameter('p1n')>=0 && (int)$request->getParameter('p1n1')>=0 && (int)$request->getParameter('p1n2')>=0 && (int)$request->getParameter('p1n3')>=0) {
			$this->getUser()->setAttribute('p1n', (int)$request->getParameter('p1n'));
			$this->getUser()->setAttribute('p1n1', (int)$request->getParameter('p1n1'));
			$this->getUser()->setAttribute('p1n2', (int)$request->getParameter('p1n2'));
			$this->getUser()->setAttribute('p1n3', (int)$request->getParameter('p1n3'));
		} else {
			$error = true;
		}

		//Produkt 2
		if ((int)$request->getParameter('p2n')>=0 && (int)$request->getParameter('p2n1')>=0 && (int)$request->getParameter('p2n2')>=0 && (int)$request->getParameter('p2n3')>=0) {
			$this->getUser()->setAttribute('p2n', (int)$request->getParameter('p2n'));
			$this->getUser()->setAttribute('p2n1', (int)$request->getParameter('p2n1'));
			$this->getUser()->setAttribute('p2n2', (int)$request->getParameter('p2n2'));
			$this->getUser()->setAttribute('p2n3', (int)$request->getParameter('p2n3'));
		} else {
			$error = true;
		}

		//Produkt 3
		if ((int)$request->getParameter('p3n')>=0 && (int)$request->getParameter('p3n1')>=0 && (int)$request->getParameter('p3n2')>=0 && (int)$request->getParameter('p3n3')>=0) {
			$this->getUser()->setAttribute('p3n', (int)$request->getParameter('p3n'));
			$this->getUser()->setAttribute('p3n1', (int)$request->getParameter('p3n1'));
			$this->getUser()->setAttribute('p3n2', (int)$request->getParameter('p3n2'));
			$this->getUser()->setAttribute('p3n3', (int)$request->getParameter('p3n3'));
		} else {
			$error = true;
		}

		//Direktverkäufe
		$dv = (int)$request->getParameter('dv');
		if ($dv >= 0) {
			$this->getUser()->setAttribute('dv', $dv);
		} else {
			$error = true;
			//echo "DV:".$dv;
		}

		if ($error) {
			//echo "ERROR:".$error;
			$this->getUser()->setFlash('error', "Bitte alle Felder ausfüllen", false);
			$this->forward('sellwish', 'index');
		} else {
			$this->redirect('production/safetystock');
			//$this->getUser()->setAttribute('progress', 40);
		}
	}
}
